package cluster

import (
	"my-godis/interface/redis"
	"my-godis/redis/reply"
)

func FlushDB(cluster *Cluster, c redis.Connection, args [][]byte) redis.Reply {
	replies := cluster.broadcast(c, args)
	var errReply reply.ErrorReply
	for _, v := range replies {
		if reply.IsErrorReply(v) {
			errReply = v.(reply.ErrorReply)
			break
		}
	}
	if errReply != nil {
		return reply.MakeErrReply("error occurs: " + errReply.Error())
	}
	return reply.MakeOkReply()
}

// FlushAll removes all data in cluster
func FlushAll(cluster *Cluster, c redis.Connection, args [][]byte) redis.Reply {
	return FlushDB(cluster, c, args)
}



